package daobeauty.interceptor.invoke.parser.operator;

import java.util.List;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

import daobeauty.util.Stack;

public class NotOperator implements Operator {
	private Operator operator;
	
	public NotOperator(Operator operator){
		this.operator = operator;
	}
	
	public Criterion createCriterion(Stack argumentStack) {
		return Restrictions.not(operator.createCriterion(argumentStack));
	}
	
	public String toHqlQuery(Stack argumentStack, List usedArguments){
		return "NOT ("+operator.toHqlQuery(argumentStack, usedArguments)+")";
	}
		
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((operator == null) ? 0 : operator.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final NotOperator other = (NotOperator) obj;
		if (operator == null) {
			if (other.operator != null)
				return false;
		} else if (!operator.equals(other.operator))
			return false;
		return true;
	}

	public int getAmountArguments() {
		return 0;
	}

	public int getTotalAmountArguments() {
		return operator.getTotalAmountArguments();
	}

	public String toTotalString() {
		return "NOT "+operator.toTotalString();
	}
	
	public String toString(){
		return toTotalString();
	}
}
